const mongoose = require('./db')


const cate = new mongoose.Schema({
    name: String
})
const classification = new mongoose.Schema({
    img: String,
    name: String,
    price: Number,
    money: Number,
    num: Number,
    cid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'cate'
    }
})

// 陆珺瑶
// 商城首页商品表
let shopSchema = new mongoose.Schema({
    img: String,
    name: String,
    price: Number,  // 原价格
    money: Number,  // 现价格
    num: Number,   // 购买数量
})
let shopModel = mongoose.model('shop', shopSchema, 'shop')

// 商城首页盒子表
let boxSchema = new mongoose.Schema({
    icon: String,
    con: String,
    color: String
})
let boxModel = mongoose.model('box', boxSchema, 'box')

// 搜索-历史记录表
let historySchema = new mongoose.Schema({
    name: String,
})
let historyModel = mongoose.model('history', historySchema, 'history')


const saveimg = new mongoose.Schema({
    id: String,
    name: String
})
const Classification = mongoose.model('classification', classification, 'classification')
const Cate = mongoose.model('cate', cate, 'cate')
const Saveimg = mongoose.model('saveimg', saveimg, 'saveimg')

// 反馈表
let feedbackSchema = new mongoose.Schema({
    con: String,
    img: String
})


// -------李大帅-------------------------------
let userschema=new mongoose.Schema({
    name:String,
    password:Number,
    face:String
})

// ----------李大帅-------------------------------

let feedbackModel=mongoose.model('feedback',feedbackSchema,'feedback')
let userModel=mongoose.model('user',userschema,'user')

// 客服
const MyOrderSchema = new mongoose.Schema({
    title: String,
    url: String,
})
const MyOrder = mongoose.model('MyOrder', MyOrderSchema, 'myorder');

let chatSchema = new mongoose.Schema({

    datatime: Date,
    user: String,
    room: String,
    roomId: String,
    isread: Boolean,
    name: String,
    msg: String,
    img: String,
    statu: {
        type: Boolean,
        default: false
    },
    // 关联user的_id
    user_id: {
        type: mongoose.Types.ObjectId,
        ref: 'user'
    }
})

const chatModel = mongoose.model('chat', chatSchema, 'chat');

module.exports = { shopModel, boxModel, historyModel, feedbackModel, chatModel, MyOrder, userModel, Classification, Cate, Saveimg }


